﻿using System;
using Codeflows;
using CodeflowsHost.Dashboard;
using Nancy.Hosting.Self;

namespace CodeflowsHost
{
    internal class CodeflowsDashboardHost : CustomServiceBase
    {
        private NancyHost _nancyHost;

        public Uri AdminUrl { get; set; }

        public CodeflowsDashboardHost()
        {
            AdminUrl = new Uri("http://localhost:1234/");    
        }

        public override void Start()
        {
            _nancyHost = new NancyHost(new CustomNancyBootstrapper(), AdminUrl);
            _nancyHost.Start();

            DiagnosticsUtility.Verbose("Admin interface now listening on {0}.", AdminUrl);
        } 

        public override void Stop()
        {
            DiagnosticsUtility.Verbose("Stopping admin interface.");
            _nancyHost.Stop();
        }

        protected override string GetServiceName()
        {
            return "Codeflows Dashboard Host";
        }
    }
}